package com.art.hystrix.controller.service.impl;

import com.art.common.utils.HttpResult;
import com.art.hystrix.controller.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author liuhb
 * @date 2020/11/17
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private RestTemplate restTemplate;
    @Value("${service-url.art-client}")
    private String userServiceUrl;
    @Override
    @HystrixCommand(fallbackMethod = "getDefaultUser")
    public HttpResult getUser(Long id) {
        String uri = userServiceUrl + "/user/user/{1}";
        HttpResult s = restTemplate.getForObject(uri, HttpResult.class, id);
        return HttpResult.ok();
    }
    public HttpResult getDefaultUser(Long id){
        return HttpResult.ok("Default User");
    }
}
